package com.tbit.uqbike.client.dto;

import cn.hutool.core.bean.BeanUtil;
import com.alibaba.fastjson.annotation.JSONField;
import lombok.Data;

/**
 * 事件上报请求
 *
 *
 * @author <a href="mailto:chen.chaoxiong@tbit.com.cn">ChenChaoXiong</a>
 * @since 2024/7/2
 */
@Data
public class EventPutDTO extends EventPutReqDTO {

    /**
     *  appId：微信openId或者支付宝user_id
     */
    private String appId;
    /**
     *  sessionId：打开一次小程序新建一次
     */
    private String sessionId;
    /**
     *  traceId：一次业务流程或者一次业务请求的唯一标识
     */
    private String traceId;
    /**
     *  brandId：品牌id
     */
    private Integer brandId;
    /**
     *  accountId：区域id
     */
    private Integer accountId;
    /**
     *  putType：上报类型。"client_put"：客户端上报，"server_filter"：服务端过滤上报, "server_put"：服务端上报
     */
    private String putType = "client_put";
    /**
     *  uri：接口路径
     */
    private String uri;
    /**
     * 请求参数，包括URL参数、表单参数、请求头等，json格式
     */
    private String requestParams;
    /**
     * 接口请求body，json格式
     */
    private String requestBody;
    /**
     * 接口响应body，json格式
     */
    private String responseBody;

    @JSONField(serialize = false)
    public static EventPutDTO getInstance(EventPutReqDTO req, CommonHeaderDTO headers) {
        EventPutDTO dto = new EventPutDTO();
        BeanUtil.copyProperties(req, dto);
        dto.setAppId(headers.getAppId());
        dto.setSessionId(headers.getSessionId());
        dto.setTraceId(headers.getTraceId());
        dto.setBrandId(headers.getBrandId());
        dto.setAccountId(headers.getAccountId());
        return dto;
    }

    @JSONField(serialize = false)
    public void setCommonHeader(CommonHeaderDTO commonHeader) {
        if (commonHeader == null) {
            return;
        }
        this.appId = commonHeader.getAppId();
        this.sessionId = commonHeader.getSessionId();
        this.traceId = commonHeader.getTraceId();
        this.brandId = commonHeader.getBrandId();
        this.accountId = commonHeader.getAccountId();
    }
}
